package com.hzit.shop.controller;

import com.hzit.common.utils.PageUtils;
import com.hzit.common.utils.R;
import com.hzit.shop.entity.ItemCatEntity;
import com.hzit.shop.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 商品类目
 *
 * @author hbxfwf
 * @email 2568783935@gmail.com
 * @date 2023-06-06 15:58:41
 */
@RestController
@RequestMapping("shop/itemcat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    /**
     * 列表
     */
    @GetMapping("/list")
        public R list(@RequestParam Map<String, Object> params){
        PageUtils page = itemCatService.queryPage(params);

        return R.ok().put("page", page);
    }
    // 根据分类id查询此分类下的子分类列表
    @GetMapping("/findByParentId/{id}")
    public R findByParentId(@PathVariable("id") String id){
        List<ItemCatEntity> itemCatEntityList = itemCatService.findByParentId(id);

        return R.ok().put("itemCatList",itemCatEntityList);
    }

    // 查询所有分类
    @GetMapping("/findAll")
    public R findAll(){
        List<ItemCatEntity> list = itemCatService.list();
        return R.ok().put("list",list);
    }
    /**
     * 信息
     */
    @GetMapping("/info/{id}")
        public R info(@PathVariable("id") String id){
		ItemCatEntity itemCat = itemCatService.getById(id);

        return R.ok().put("itemCat", itemCat);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
        public R save(@RequestBody ItemCatEntity itemCat){
		itemCatService.save(itemCat);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
        public R update(@RequestBody ItemCatEntity itemCat){
		itemCatService.updateById(itemCat);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
        public R delete(@RequestBody String[] ids){
		itemCatService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
